﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" />
    <link rel="stylesheet" href="../styles/serverwindows.css" />
    <script type="text/javascript" src="../js/jquery-3.7.0.min.js"></script>
    <script>
        window.onload = function () {
            var data = JSON.parse(Formium.external.serverwindow.data);
            $.each(data, (index, item) => {
                $('#serverId').append($('<option>', {
                    value: item.Id,
                    text: item.SiteLabel
                }));
            })
        }
    </script>
</head>
<body>
    <!-- HTML Content -->
    <script src="../layui/layui.js"></script>
    <script>
        // Usage
        layui.use(function () {
            var layer = layui.layer;
            var form = layui.form;
            // Welcome
            layer.msg('Hello World', { icon: 6 });
            form.on('select(serverId)', function (data) {
                var elem = data.elem; // 获得 select 原始 DOM 对象
                var value = data.value; // 获得被选中的值
                var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
                //layer.msg(this.innerHTML + ' 的 value: ' + value); // this 为当前选中 <option> 元素对象
                if (typeof value == 'string' && value.length <= 0) {
                    return false;
                }
                var res = Formium.external.serverwindow.GetSeverModel(value);
                var model = JSON.parse(res);

                form.val('refserverform', {
                    "Id": model.Id,
                    "SiteLabel": model.SiteLabel,
                    "SiteName": model.SiteName,
                    "SitePort": model.SitePort,
                    "SitePath": "女"
                });

            });
        });
    </script>
    <div class="ml_container">
        <div class="layui-form-pane">
            <form class="layui-form layui-form-pane" lay-filter="refserverform">
                <div class="layui-form-item">
                    <label class="layui-form-label">网站名称：</label>
                    <div class="layui-input-block">
                        <select lay-filter="serverId" id="serverId">
                            <option selected value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站标识：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Id" placeholder="网站标识" disabled class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">服务名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="SiteName" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站端口：</label>
                    <div class="layui-input-block">
                        <input type="text" name="SitePort" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站路径：</label>
                    <div class="layui-input-block">
                        <input type="text" name="SitePath" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                    </div>
                </div>
            </form>
        </div>
        <div class="ml_container_bootom">
            <button type="button" class="layui-btn  ml_savebtn" onclick="save()">保存</button>
        </div>
    </div>

</body>
</html>